﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using System.Net;

namespace Silmoon.DNS.Monitoring
{
    public class Communicator
    {
        GBC g = null;
        public Communicator(GBC g)
        {
            this.g = g;
        }
        public void AsyncNotifySimpleState(MonitorResult result)
        {
            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
            wc.DownloadStringAsync(new Uri(g.configure.webapi + "?apitype=system&action=changerecordstate&_id=" + result.RecordOId + "&state=" + result.State + "&statecode=" + result.StateCode));
        }

        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (e.Error != null)
                {
                    g.onThreadException(this, new System.Threading.ThreadExceptionEventArgs(e.Error));
                }
                else
                {

                }
            }
            catch { }
            ((WebClient)sender).Dispose();
        }
    }
}
